	//注册表单的非空校验
	function checkForm() {
		var username = document.getElementById("username").value;
	
		if (username == null || username == "") {
			alert("用户名不能为空");
			return false;
		}
	
		var password = document.getElementById("password").value;
		if (password == null || password == "") {
			alert("密码不能为空");
			return false;
		}
	
		var repassword = document.getElementById("repassword").value;
		if (repassword == null || repassword == "") {
			alert("确认密码不能为空");
			return false;
		}
		if (repassword != password) {
			alert("两次密码输入不一致");
			return false;
		}
	
		var email = document.getElementById("email").value;
		if (email == null || email == "") {
			alert("邮箱不能为空");
			return false;
		}
		var phone = document.getElementById("phone").value;
		if (phone == null || phone == "") {
			alert("电话不能为空");
			return false;
		}
		var validatecode = document.getElementById("validatecode").value;
		if (validatecode == null || validatecode == "") {
			alert("验证码不能为空");
			return false;
		}
	}
	
	// ajax校验用户名是否存在
	function checkUserName() {
		var reg = /^[a-zA-Z]\w{2,11}$/
		var username = document.getElementById("username").value;
		//alert(username);
		var message = document.getElementById("u");

		var f = reg.test(username);
		if (f==false){
			message.innerText = "用户名格式不对";
			message.style.color = "red";
			return;
		}
        var xmlHTTP = creatXMLHttpRequest();
        var username = document.getElementById("username").value;
        xmlHTTP.open("GET","/ajax/findUsernameServlet?username="+username,true);
        xmlHTTP.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        xmlHTTP.send("username="+username+"&time="+new Date());
        xmlHTTP.onreadystatechange = function () {
            var msg = document.getElementById("msg")
            if (xmlHTTP.readyState == 4 && xmlHTTP.status==200){
                var flag = xmlHTTP.responseText;
                if (flag == "true"){
                    msg.innerText="用户已经存在";
                    msg.style.color = "gray"
                } else {
                    msg.innerText="用户名可注册"
                    msg.style.color="green"
                }
            }
        }
		// 3.打开连接(为了避免浏览器的缓存，需要加一个时间参数)
		xmlhttp.open("GET","${pageContext.request.contextPath}/findByUsername?a="+ new Date().getTime()+"&username="+username+"", true);
		// 4.发送请求
		xmlhttp.send(null);
	
	}
	
	// 创建XMLHttpRequest对象
	function createXMLHttpRequest() {
		try {
			return new XMLHttpRequest();
		} catch (e) {
			try {
				return new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					return new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {
					alert("你用什么浏览器呢？");
					throw e;
				}
			}
		}
	};
	//切换验证码
	function changecode(){
		var img = document.getElementById("validateimage");
		img.src = "${pageContext.request.contextPath}/codeaction?a="+new Date().getTime();
	}
	
	
	
	
	
	
	
	